package use_google;



import java.io.UnsupportedEncodingException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Response;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.JsonRequest;

/**
 * Volley adapter for JSON requests that will be parsed into Java objects by Gson.
 */
public class jsonOArequest extends JsonRequest<JSONObject> {

	  public jsonOArequest(int method, String url, JSONObject jsonRequest, Response.Listener<JSONObject> listener, Response.ErrorListener errorListener)
	  {
	    super(method, url, jsonRequest == null ? null : jsonRequest.toString(), listener, 
	      errorListener);
	  }

	  public jsonOArequest(String url, JSONObject jsonRequest, Response.Listener<JSONObject> listener, Response.ErrorListener errorListener)
	  {
	    this(jsonRequest == null ? 0 : 1, url, jsonRequest, 
	      listener, errorListener);
	  }

	  protected Response<JSONObject> parseNetworkResponse(NetworkResponse response)
	  {
	    try {
	      String jsonString = 
	        new String(response.data, HttpHeaderParser.parseCharset(response.headers));
	      
	      return Response.success(new JSONObject(jsonString), 
	    		  			HttpHeaderParser.parseCacheHeaders(response));
	      
	      
	    } catch (UnsupportedEncodingException e) {
	      return Response.error(new ParseError(e)); 
	      }
	    catch (JSONException je) {
	    	return Response.error(new ParseError(je));
	    }
	    
	  }
	  
  
}